package com.dissertation.action;

import com.dissertation.annotation.CheckBindingResult;
import com.dissertation.model.Tag;
import com.dissertation.pojo.Message;
import com.dissertation.service.ITagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping( "tag" )
public class TagController {


    @Resource( name = "checkTagImpl" )
    ITagService tagService;

    @PostMapping
    @CheckBindingResult
    Message insert( @RequestBody @Validated Tag tag,
                    BindingResult bindingResult ) {
        return tagService.save( tag );
    }


    @PutMapping
    @CheckBindingResult
    Message update( @RequestBody @Validated Tag tag,
                    BindingResult bindingResult ) {

        return tagService.update( tag );
    }


    @GetMapping
    Message findAll() {
        return tagService.findAll();
    }

    @PostMapping("delete")
    Message delete(@RequestBody @Validated Tag tag,BindingResult bindingResult){
        return tagService.delete(tag);

    }


}
